﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class MP_MasFieldPositionGroups : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        private IFieldGroupBLL groupBLL = new FieldGroupBLL();
        private IEmployeeTypeBLL empTypeBLL = new EmployeeTypeBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                bindEmpType();
                //LoadDataGrid();
            }
        }
        public void LoadDataGrid()
        {
            Nullable<int> EmpTypeSeq = ddlEmployeeType.SelectedValue.Length > 0 ? Int32.Parse(ddlEmployeeType.SelectedValue) : (int?)null;

            IList<FieldGroupInfo> Info = groupBLL.ListFieldGroups(null, EmpTypeSeq);
            RadGrid1.DataSource = Info;
            RadGrid1.DataBind();
        }
        private void bindEmpType()
        {
            try
            {
                IList<EmployeeTypeInfo> infoList = empTypeBLL.ListEmployeeTypes();
                ddlEmployeeType.DataSource = infoList;
                ddlEmployeeType.DataBind();

            }
            catch
            {

            }
        }
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Sequence"]);
                
                groupBLL.Delete(seq, ssMng.EmpSeqI);
             }

            LoadDataGrid();
        }

        protected void ddlEmployeeType_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            LoadDataGrid();
        }
    }
}
